<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="HandheldFriendly" content="true" />
    <meta name="MobileOptimized" content="320" />
    <link rel="stylesheet" type="text/css" href="css/reset.css" />
    <link rel="stylesheet" type="text/css" href="css/login.css" />
    <link rel="stylesheet" href="./css/jiazai.css">
    <title>登陆</title>
</head>

<body>
    <div id='app'>

        <!-- 加载中动画 -->
        <div class='jiazai' v-if='jiazai'>
            <img src="./img/jia-ani.gif" width="50px" height="50px">
        </div>
        <!-- 加载中动画 -->

        <div class='login' @click='console.log(plus.webview.all().length)'>
            <img src="./img/logo-white.png" width="100%" height="100%">
        </div>
        <div class="input-wrap">
            <div class='input'>
                <img src="./img/login-phone.png" height="24px">
                <input type="text" v-model='user.phone' placeholder="请输入手机号码">
            </div>
            <div class='input'>
                <img src="./img/login-pas.png" height="24px">
                <input :type="passType" v-model='user.password' placeholder="请输入密码">
                <img @click='passType=="password"?passType="text":passType="password"' :src="passType=='password'?'./img/hide-pas.png':'./img/show-pas.png'" width="24px">
            </div>
            <button @click='goLogin'>登陆</button>
            <p @click='forgetPass'>忘记密码?</p>
        </div>
        <div class='regist' id='regi'>
            <span>没有账号？</span>
            <span @click='regis' style='color:#3574FA;'>去注册</span>
        </div>
    </div>
    <script src="js/comm.js" type="text/javascript" charset="utf-8"></script>
    <script src="js/igexin.js"></script>
    <script src="js/jquery.min.js"></script>
    <script src="js/base64.js"></script>
    <script src="js/vue.min.js"></script>
    <script src="js/update.js"></script>
    <script src="js/indexBack.js" type="text/javascript" charset="utf-8"></script>
    <script>
        function plusReady() {
            var tool = new igexinTool();
            tool.bindAlias("ykj");
        };
        if (window.plus) {
            plusReady();
        } else {
            document.addEventListener('plusready', plusReady, false);
        }
        var app = new Vue({
            el: '#app',
            data: {
                jiazai: false,
                user: {
                    //电话
                    phone: '',
                    //密码
                    password: '',
                },
                //控制密码的显示
                passType: 'password'
            },
            mounted: function() {
                var This = this;
                This.$nextTick(function(){
            		_handBottom(document.getElementById('regi'));
            	});
                setTimeout(function() {
                    function plusReady() {
                        plus.runtime.getProperty(plus.runtime.appid, function(info) {
                            This.jiazai = true;
                            _post(UPDATE, {
                                var: info.version
                            }, function(item) {
                                This.jiazai = false;
                                if (item.status == 1) {
                                    install(item.back);
                                } else {
                                    var user = localStorage.getItem('user');
                                    var shouPassword = localStorage.getItem('shouPassword');
                                    if (user && shouPassword) {
                                        _openHref('veri-shou-password.html', 'veriShouPassword', 'none');
                                        return;
                                    }
                                    if (user) {
                                        _openHref('index.html', 'index', 'none');
                                        return;
                                    }
                                }
                            });
                        });
                    }
                    // 判断扩展API是否准备，否则监听'plusready'事件
                    if (window.plus) {
                        plusReady();
                    } else {
                        document.addEventListener('plusready', plusReady, false);
                    }
                }, 200);
            },
            methods: {
                //忘记密码
                forgetPass: function() {
                    _openHref('forget-password.html', 'forgetPassword');
                },
                //去登陆
                goLogin: function() {
//                  if (!_checkMobile(this.user.phone)) {
//                      _toast('请输入正确的手机号码');
//                      return;
//                  }
                    if (this.user.password.length == 0) {
                        _toast('请输入密码');
                        return;
                    }
                    var patt = /^\w+$/;
                    if (!patt.test(this.user.password)) {
                        _toast('密码不正确');
                        return;
                    }
                    this.jiazai = true;
                    var This = this;
                    var info = plus.push.getClientInfo();
                    _bas64Post(LOGIN, {
                        userphone: this.user.phone,
                        password: this.user.password,
                        clientid: info.clientid
                    }, function(data) {
                        This.jiazai = false;
                        if (data.status == 1) {
                            if (data.back.is_frozen == 1) {
                                alert('您的账号已被冻结，请联系管理员');
                                return;
                            }
                            _toast('登陆成功');
                            if (data.back.userpic) {
                                data.back.avatar = HTTP + data.back.userpic;
                            }
                            localStorage.setItem('user', JSON.stringify(data.back));
                            _openHref('index.html', 'index');
                        } else {
                            _toast(data.msg);
                        }
                    });
                },
                //去注册-打开注册协议
                regis: function() {
                    _openHref('regiset-input-phone.html', 'regisetInputPhone');
                },
            }
        });
    </script>

</body>

</html>